/**
 * author:Administrator
 * date:2016/3/25
 * desc: 向redis中发布信息
 */

'use strict';

let redis = require('redis');
let config = require('../config.js');

// subA subscribe single channel
let channelX = require('./pubsubCfg.js').channelX;
let subA = redis.createClient(config.redis);
// event
// message subscribe unsubscribe

subA.on('subscribe', function (channel, cout) {
  console.log('subA subscribe done');
});
subA.on('message', function (channel, msg) {
  console.log("subA channel=%s, msg=%s ", channel, msg);
});
subA.subscribe(channelX);

// pmessage psubscribe punsubscribe  p=pattern
// subB subscribe regex "foo.bar.*"
let subB = redis.createClient(config.redis);
subB.on('psubscribe', function (channel, cout) {
  console.log('subB subscribe done');
});
subB.on('pmessage', function (pattern, channel, msg) {
  console.log("subB pattern=%s, channel=%s, msg=%s ", pattern, channel, msg);
});
subB.psubscribe("foo.bar.*"); // pattern subscribe
